﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace NusyaTester {
    class TestHolder {
        private List<TestEntry> Entries;
        public int currIndex { get; private set; }
        public int RightCount { get; private set; }
        public int WrongCount { get; private set; }
        public TestHolder(){
            Entries = new List<TestEntry>();
            currIndex = 0;
        }
        public void Load(string FileName) {
            StreamReader sr = new StreamReader(FileName, Encoding.GetEncoding(0));
            Entries.Clear();
            while (!sr.EndOfStream) {
                TestEntry te = new TestEntry();
                te.Load(sr);
                Entries.Add(te);
            }
            sr.Close();
        }
        public int Count { get { return Entries.Count; } }  

        public bool EndOfTest {
            get {
                if (currIndex >= Entries.Count-1) return true;
                return false;
            }
        }
        public TestEntry currentEntry {
            get {
                if (currIndex >= Entries.Count) return Entries[currIndex-1];
                return Entries[currIndex];
            }
        }
        public void Next() { currIndex++; }
        public void Rewind() { currIndex = 0; }

        public IEnumerator<TestEntry> GetEnumerator() {
            foreach (TestEntry te in Entries) {
                yield return te;
            }
        }

        public IEnumerable<TestEntry> BadAnswers {
            get {
                foreach (TestEntry te in Entries) {
                    if (te.isCorrect == false)
                        yield return te;
                }
            }
        }

        public void calculateResut() {
            RightCount = 0;
            WrongCount = 0;
            foreach (TestEntry te in Entries) {
                if (te.isCorrect) RightCount++;
                else WrongCount++;
            }
        }

    }
}
